package com.bwda.dsrs.systemservice.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: yangjun
 * @create: 2019-06-14 16:55
 */
public class JsonUtil {
    /**
     * 描述：组装json格式返回结果 创建人：fengsen 创建时间：2012-8-22 备注：.
     * @param isOk
     * @param resCode
     * @param errorMsg
     * @param obj
     * @return
     */
    public static Map<String, Object> createJson(boolean isOk, int resCode, String errorMsg, Object obj) {
        Map<String, Object> jsonMap = new HashMap<String, Object>(16);
        jsonMap.put("result", isOk ? "ok" : "fail");
        jsonMap.put("rescode", resCode);
        jsonMap.put("msg", errorMsg);
        jsonMap.put("data", obj);
        return jsonMap;
    }

    /**
     * @param isOk
     * @param resCode
     * @param errorMsg
     * @param obj
     * @return
     */
    public static String createJsonString(boolean isOk, int resCode, String errorMsg, Object obj) {
        Map<String, Object> jsonMap = createJson(isOk, resCode, errorMsg, obj);
        JSONObject json=new JSONObject(jsonMap);
        return json.toJSONString();
    }

}
